home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 100435.736@compuserve.com (David A. Mair)
- Newsgroups: comp.lang.c++
- Subject: Re: Interrupts in C++
- Date: Fri, 02 Feb 1996 15:22:52 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4eta8j$kb1@dub-news-svc-2.compuserve.com>
- References: <310FBF6A.6692@sask.aecl.ca>
- NNTP-Posting-Host: dd65-006.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Mark Kotyk <kotykm@sask.aecl.ca> wrote:
-
- >I've been trying to get a good Com class going, but soon found
- >out there is no easy way to get a Dos interrupt handler to sit
- >in a class, and have access to private data members.
-
- >Any help. I have picked up a package that did allow interrupts
- >to be created dynamically, but it was rather large.
-
- At first I thought you were off topic but considering the question of
- allowing a class to handle an asynchronously generated event that must
- be associated with a particular instance of a class is a reasonable
- C++ question, I suppose.
-
- Here is how I would do what you want. Make the interrupt handler a
- static member function and add a static member that is an array of
- pointers to the handler class. For example:
-
- class CComHandler
- {
-
- static CComHandler *Handlers[8]; // Handle up to 8 COM porst
-
- public:
- static void IntHandler(); // Interrupt handler
-
- void IntOnThisPort();
- };
-
- Inthandler() can find the interrupt that was generated from the
- hardware in the computer. This can be used to generate an integer
- quantity to be used as an index into the array. The pointer at the
- index can be used to call the actual interrupt handler for the class,
- viz:
-
- static void CComHandler::IntHandler()
- {
- // Use the hardware to get the COM port as a number between 1 and 8
- PortNum = (Some I/O operations);
-
- // Find the right handler
- if (Handlers[PortNum] != NULL)
- {
- Handlers[PortNum]->IntOnThisPort();
- }
-
- // Clear up the interrupt here or it will never be cleared
- }
-
- This is by no means an exhaustive list of considerations, clearly the
- array will have to be initialised to NULLs in order to be sure that
- the conditional test in IntHandler() works. Also, I have deliberately
- avoided the business of PC specific information as much as possible.
- Finally, I doubt my C++ is good enough for this to have no errors of
- style or compatibility with the draft standard.
-
- Regards
- David.
-
-